package light.head.dao.el;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import light.head.constant.Parm;
import light.head.enm.RESULT;
import light.head.framework.base.BaseDAO;
import light.head.framework.entity.PageBean;
import light.head.model.el.ClassRoom;

import org.springframework.stereotype.Service;

@Service
public class ClassRoomDAO extends BaseDAO<ClassRoom, Integer> {

	public RESULT findByMap(List<Integer> ocs, Map<String, String> map, PageBean pageBean){
		if(ocs == null) return null;
		List<Object> list = new ArrayList<Object>();
		StringBuffer sql = new StringBuffer("FROM ClassRoom r WHERE r.oc IN (");
		for (Integer i : ocs) {
			sql.append("?,");
			list.add(i);
		}
		sql.deleteCharAt(sql.length() - 1).append(")");
		if(map != null){
			String name = map.get(Parm.NAME);
			String deleted = map.get(Parm.DELETED);
			
			if(isNotNull(name)){
				sql.append(" AND r.name LIKE ?");
				list.add("%" + name + "%");
			}
			if(isNotNull(deleted)){
				System.out.println(deleted);
				sql.append(" AND r.deleted = ?");
				list.add(Boolean.parseBoolean(deleted));
			}
		}
		sql.append(" ORDER BY r.code DESC");
		return findToPageBean(sql.toString(), pageBean, list);
	}
	
}
